
#include <iostream>
#include <fstream>
#include "lklist.h"

using namespace std;

typedef int elemtype;
typedef lklisttpl<elemtype> lklist;

void delelements( lklist *, elemtype, elemtype );

int main()
{
    ifstream in("in.txt");
    vector<int> v;
    lklist *h;
    int i, n;
    int t;

    in >> n;
    for ( i = 0; i < n; i++ ){
	in >> t;
	v.push_back(t);
    }

    h = createlk<lklist,elemtype>( v, WITHHEAD );
    printlk( h, WITHHEAD ); cout << endl;
    delelements( h, 1, 20 );
    printlk( h, WITHHEAD ); cout << endl;
    destorylk( h, WITHHEAD );

    return 0;
}

void delelements( lklist *h, elemtype mink, elemtype maxk )
{
    lklist *p, *q, *r;
    
    if( mink >= maxk ) return;
    
    p = h;
    while( p->next && p->next->data <= mink )
        p = p->next;
        
    q = p->next;
    while( q && q->data < maxk ) {
        r = q;
        q = q->next;
        delete r;
    }
    
    p->next = q;
    
    return;
}
